package com.ddyx.service.product.app.config;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * <p>
 *      Swagger配置类-运营平台-接口文档-接口测试
 *      网关启动完成可以访问以下地址,多模块服务必须要在每个服务中单独配置生效
 *      http://localhost:9001/doc.html      bootstrap-UI风格
 *      http://localhost:9001/swagger-ui.html   默认UI风格
 *      http://localhost:9001/v2/api-docs   接口文档json格式
 * </p>
 * class: SwaggerConfig.java
 * author: agula
 * since: 2019-07-11  11:21
 */
@Slf4j
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 创建API
     */
    @Bean(name = "product-swagger")
    public Docket createRestApi() {
        log.info("Swagger地址：" + "http://localhost:9001/doc.html");
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
                //.groupName("全部模块");
    }

    /**
     * 添加摘要信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()// 用ApiInfoBuilder进行定制
                .title("叮当科技-系统2.0接口调试及API文档")// 设置标题
                .description("该模块为商品服务模块，作用于前端接口调试服务及文档浏览，包含所有与商品服务相关的API接口。")// 描述
                .contact(new Contact("agula", "http://www.retail.vip", "qiyifi@126.com"))// 作者信息
                .version("2.0")// 版本
                .build();
    }


}
